package com.qiangqiang.service;

import com.qiangqiang.dto.VisitDTO;
import com.qiangqiang.entity.Visit;
import com.qiangqiang.repository.VisitRepository;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

/**
 * Created by q on 2018/2/15.
 */
@Slf4j
@Service
public class VisitService {

    @Autowired
    private VisitRepository visitRepository;

    public Visit add(Visit visit){
        return visitRepository.save(visit);
    }

    public List<VisitDTO> findAllByTimeQuantum(String startTime, String endTime) {
        return visitRepository.queryByTimeQuantum(startTime, endTime).stream()
                .map(e -> {
                    VisitDTO visitDTO = new VisitDTO();
                    BeanUtils.copyProperties(e, visitDTO);
                    return visitDTO;
                }).collect(Collectors.toList());
    }

    public List<VisitDTO> findAllBySid(String sId){
        return visitRepository.queryAllBySId(sId).stream()
                .map(e->{
                  VisitDTO visitDTO=new VisitDTO();
                  BeanUtils.copyProperties(e,visitDTO);
                  return visitDTO;
                }).collect(Collectors.toList());
    }

}
